package com.apes.hr.base.repository;


import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.hr.base.model.WorkPost;
import com.apes.hr.base.model.WorkPostGroup;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * @author HuJianLin
 * @create 2018-04-28 16:07
 */
public interface WorkPostRepository extends CustomRepository<WorkPost, String> {


    @Query("select T from WorkPost T where 1 = 1 and valid = 1  and (id like %:value%  or name like %:value%) ")
    Page<WorkPost> find(@Param("value") String value, Pageable pageable);

    @Query("select T from WorkPost T where 1 = 1 and valid = 1  and  name =:value ")
    WorkPost findByName(@Param("value") String value);

    @Query("select T from WorkPost T where id = :value or name = :value")
    WorkPost find(@Param("value") String value);

    @Query(value = "SELECT B.POST_GROUP_ID FROM HR_EMPLOYEE A,HR_WORK_POST B WHERE A.NAME = :name AND A.POST_ID = B.ID ",nativeQuery = true)
    String findByPerson(@Param("name") String name);
}
